package com.shenxuchen.crm.service;

import com.shenxuchen.crm.exception.CRMException;
import com.shenxuchen.crm.mapper.ActivityMapper;
import com.shenxuchen.crm.mapper.ActivityRemarkMapper;
import com.shenxuchen.crm.pojo.Activity;
import com.shenxuchen.crm.pojo.ActivityRemark;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Resource
    private ActivityMapper activityMapper;

    @Resource
    private ActivityRemarkMapper activityRemarkMapper;

    public List getAll() {
        return activityMapper.getAll();
    }

    public void save(Activity activity) {
        activityMapper.save(activity);
    }

    public Activity getById(String id) {
        return activityMapper.getById(id);
    }

    public void edit(Activity activity) {
        activityMapper.edit(activity);
    }

    public void delete(String[] ids) {
        try {
            activityMapper.delete(ids);
        } catch (Exception e) {
            throw new CRMException("有关联数据，无法删除！");
        }
    }

    public List getRemarks(String actId) {
        return activityRemarkMapper.getRemarks(actId);
    }

    public void saveRemark(ActivityRemark activityRemark) {
        activityRemarkMapper.save(activityRemark);
    }

    public void deleteRemark(String id) {
        activityRemarkMapper.delete(id);
    }

    public void editRemark(ActivityRemark activityRemark) {
        activityRemarkMapper.edit(activityRemark);
    }

    public void saveList(List<Activity> activities) {
        activityMapper.saveList(activities);
    }
}
